/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;

import com.feiyue.helper.AnimationTabHost;
import com.umeng.analytics.MobclickAgent;

public class MainTabActivity extends TabActivity implements
		View.OnTouchListener, GestureDetector.OnGestureListener {
	private static final String BOOKCITY = "bookcity";
	private static final String BOOKFRIEND = "bookfriend";
	private static final String BOOKSTAND = "bookstand";
	private static final String MORE = "more";
	public int count = 0;
	private int firstTabIndex = -1;
	private int fourthTabIndex = -1;
	private LinearLayout linearButton_bookcity;
	private LinearLayout linearButton_bookfriend;
	private LinearLayout linearButton_bookstand;
	private LinearLayout linearButton_more;
	private GestureDetector mGestureDetector;
	private int minVelocity = 150;
	private RadioButton radioButton_bookcity;
	private RadioButton radioButton_bookfriend;
	private RadioButton radioButton_bookstand;
	private RadioButton radioButton_more;
	private int secondTabIndex = -1;
	AnimationTabHost tabHost;
	private int thirdTabIndex = -1;
	private int verticalMinDistance = 200;

	private void initiateActivity()
  {
    setTheme(16973837);
    setContentView(R.layout.tab_bottom);
    this.tabHost = ((AnimationTabHost)findViewById(android.R.id.tabhost));
    this.mGestureDetector = new GestureDetector(this);
    LinearLayout localLinearLayout = (LinearLayout)findViewById(R.id.tabbottom);
    localLinearLayout.setOnTouchListener(this);
    localLinearLayout.setLongClickable(true);
    initialBookShelf();
    this.linearButton_bookstand = ((LinearLayout)findViewById(R.id.linear_button_bookstand));
    this.radioButton_bookstand = ((RadioButton)findViewById(R.id.radio_button_bookstand));
    this.radioButton_bookstand.setOnClickListener(new View.OnClickListener()
    	    {
        public void onClick(View paramView)
        {
          MainTabActivity.this.tabHost.setCurrentTab(MainTabActivity.this.firstTabIndex);
          MainTabActivity.this.go2this("bookstand");
        }
      });
    this.linearButton_bookcity = ((LinearLayout)findViewById(R.id.linear_button_bookcity));
    this.radioButton_bookcity = ((RadioButton)findViewById(R.id.radio_button_bookcity));
    this.radioButton_bookcity.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View paramView)
        {
          MainTabActivity.this.tabHost.setCurrentTab(MainTabActivity.this.secondTabIndex);
          MainTabActivity.this.go2this("bookcity");
        }
      });
    this.linearButton_bookfriend = ((LinearLayout)findViewById(R.id.linear_button_community));
    this.radioButton_bookfriend = ((RadioButton)findViewById(R.id.radio_button_community));
    this.radioButton_bookfriend.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View paramView)
        {
          MainTabActivity.this.tabHost.setCurrentTab(MainTabActivity.this.thirdTabIndex);
          MainTabActivity.this.go2this("bookfriend");
        }
      });
    this.linearButton_more = ((LinearLayout)findViewById(R.id.linear_button_more));
    this.radioButton_more = ((RadioButton)findViewById(R.id.radio_button_more));
    this.radioButton_more.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View paramView)
        {
          MainTabActivity.this.tabHost.setCurrentTab(MainTabActivity.this.fourthTabIndex);
          MainTabActivity.this.go2this("more");
        }
      });
    this.tabHost.setCurrentTab(this.firstTabIndex);
    go2this("bookstand");
    this.tabHost.setOpenAnimation(true);
  }

	public boolean dispatchKeyEvent(KeyEvent paramKeyEvent) {
		if ((paramKeyEvent.getKeyCode() == 4)
				&& (paramKeyEvent.getAction() == 0)) {
			if (this.count == 0) {
				this.count = (1 + this.count);
				Toast.makeText(getApplicationContext(), "鍐嶆寜涓�閫�嚭椋為槄灏忚", 0).show();
				new Handler().postDelayed(new Runnable() {
					public void run() {
						MainTabActivity.this.count = 0;
					}
				}, 5000L);
				return true;
			}
			finish();
			return true;
		}
		return super.dispatchKeyEvent(paramKeyEvent);
	}

	public boolean dispatchTouchEvent(MotionEvent paramMotionEvent) {
		if (Build.VERSION.SDK_INT >= 14) {
			if (!(this.mGestureDetector.onTouchEvent(paramMotionEvent)))
				return super.dispatchTouchEvent(paramMotionEvent);
			return true;
		}
		return super.dispatchTouchEvent(paramMotionEvent);
	}

	protected void go2this(String s)
    {
        if (!s.equals("bookstand")) {
            if (s.equals("bookcity"))
            {
                linearButton_bookstand.setBackgroundDrawable(null);
                linearButton_bookcity.setBackgroundColor(0xffef7600);
                linearButton_bookfriend.setBackgroundDrawable(null);
                linearButton_more.setBackgroundDrawable(null);
                radioButton_bookstand.setTextColor(0xff999999);
                radioButton_bookcity.setTextColor(-1);
                radioButton_bookfriend.setTextColor(0xff999999);
                radioButton_more.setTextColor(0xff999999);
                radioButton_bookstand.setChecked(false);
                radioButton_bookcity.setChecked(true);
                radioButton_bookfriend.setChecked(false);
                radioButton_more.setChecked(false);
            } else
            if (s.equals("bookfriend"))
            {
                linearButton_bookstand.setBackgroundDrawable(null);
                linearButton_bookcity.setBackgroundDrawable(null);
                linearButton_bookfriend.setBackgroundColor(0xffef7600);
                linearButton_more.setBackgroundDrawable(null);
                radioButton_bookstand.setTextColor(0xff999999);
                radioButton_bookcity.setTextColor(0xff999999);
                radioButton_bookfriend.setTextColor(-1);
                radioButton_more.setTextColor(0xff999999);
                radioButton_bookstand.setChecked(false);
                radioButton_bookcity.setChecked(false);
                radioButton_bookfriend.setChecked(true);
                radioButton_more.setChecked(false);
            } else
            if (s.equals("more"))
            {
                linearButton_bookstand.setBackgroundDrawable(null);
                linearButton_bookcity.setBackgroundDrawable(null);
                linearButton_bookfriend.setBackgroundDrawable(null);
                linearButton_more.setBackgroundColor(0xffef7600);
                radioButton_bookstand.setTextColor(0xff999999);
                radioButton_bookcity.setTextColor(0xff999999);
                radioButton_bookfriend.setTextColor(0xff999999);
                radioButton_more.setTextColor(-1);
                radioButton_bookstand.setChecked(false);
                radioButton_bookcity.setChecked(false);
                radioButton_bookfriend.setChecked(false);
                radioButton_more.setChecked(true);
            }
        } else {
            linearButton_bookstand.setBackgroundColor(0xffef7600);
            linearButton_bookcity.setBackgroundDrawable(null);
            linearButton_bookfriend.setBackgroundDrawable(null);
            linearButton_more.setBackgroundDrawable(null);
            radioButton_bookstand.setTextColor(-1);
            radioButton_bookcity.setTextColor(0xff999999);
            radioButton_bookfriend.setTextColor(0xff999999);
            radioButton_more.setTextColor(0xff999999);
            radioButton_bookstand.setChecked(true);
            radioButton_bookcity.setChecked(false);
            radioButton_bookfriend.setChecked(false);
            radioButton_more.setChecked(false);
        }
    }

	protected void initialBookShelf() {
		Intent localIntent1 = new Intent(this, BookShelfActivity.class);
		TabHost.TabSpec localTabSpec1 = this.tabHost
				.newTabSpec("BookShelfActivity")
				.setIndicator("BookShelfActivity", null)
				.setContent(localIntent1);
		this.tabHost.addTab(localTabSpec1);
		this.firstTabIndex = 0;
		Intent localIntent2 = new Intent(this, BookCityTabActivity.class);
		TabHost.TabSpec localTabSpec2 = this.tabHost
				.newTabSpec("BookStoreTabActivity")
				.setIndicator("BookStoreTabActivity", null)
				.setContent(localIntent2);
		this.tabHost.addTab(localTabSpec2);
		this.secondTabIndex = 1;
		Intent localIntent3 = new Intent(this, BookFriendActivity.class);
		TabHost.TabSpec localTabSpec3 = this.tabHost
				.newTabSpec("BookFriendActivity")
				.setIndicator("BookFriendActivity", null)
				.setContent(localIntent3);
		this.tabHost.addTab(localTabSpec3);
		this.thirdTabIndex = 2;
		Intent localIntent4 = new Intent(this, MoreActivity.class);
		TabHost.TabSpec localTabSpec4 = this.tabHost.newTabSpec("MoreActivity")
				.setIndicator("MoreActivity", null).setContent(localIntent4);
		this.tabHost.addTab(localTabSpec4);
		this.fourthTabIndex = 3;
	}

	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		initiateActivity();
		MobclickAgent.setDebugMode(true);
	}

	protected void onDestroy() {
		System.exit(0);
		super.onDestroy();
	}

	public boolean onDown(MotionEvent paramMotionEvent) {
		return false;
	}

	public boolean onFling(MotionEvent motionevent, MotionEvent motionevent1, float f, float f1)
    {
        boolean flag;
        float f2;
        flag = true;
        f2 = Math.abs(motionevent.getX() - motionevent1.getX()) / Math.abs(motionevent.getY() - motionevent1.getY());
        if (motionevent.getX() - motionevent1.getX() <= 0.0F || (double)f2 - 2.5D <= 0.0D) {
            if (motionevent.getX() - motionevent1.getX() < 0.0F && (double)f2 - 2.5D > 0.0D)
            {
                if (tabHost.getCurrentTab() == fourthTabIndex)
                {
                    tabHost.setCurrentTab(thirdTabIndex);
                    go2this("bookfriend");
                }
                if (tabHost.getCurrentTab() == thirdTabIndex)
                {
                    tabHost.setCurrentTab(secondTabIndex);
                    go2this("bookcity");
                }
                if (tabHost.getCurrentTab() == secondTabIndex)
                {
                    //TODO
//                    if (BookCityTabActivity.currenttab >= flag)
                    if (BookCityTabActivity.currenttab >= 1)
                    {
                        flag = false;
                    } else
                    {
                        tabHost.setCurrentTab(firstTabIndex);
                        go2this("bookstand");
                    }
                }
                if (tabHost.getCurrentTab() == firstTabIndex);
                
                
            }
        } else {
            if (tabHost.getCurrentTab() != firstTabIndex) {
                if (tabHost.getCurrentTab() == secondTabIndex)
                {
                    if (BookCityTabActivity.currenttab < 3)
                    {
                        flag = false;
                    } else
                    {
                        tabHost.setCurrentTab(thirdTabIndex);
                        go2this("bookfriend");
                    }
                } else if (tabHost.getCurrentTab() == thirdTabIndex)
                {
                    tabHost.setCurrentTab(fourthTabIndex);
                    go2this("more");
                }
                
                flag = false;
                
            } else {
                tabHost.setCurrentTab(secondTabIndex);
                go2this("bookcity");
                
            }
        }
        
        return flag;
    }

	public void onLongPress(MotionEvent paramMotionEvent) {
	}

	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public boolean onScroll(MotionEvent paramMotionEvent1,
			MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2) {
		return false;
	}

	public void onShowPress(MotionEvent paramMotionEvent) {
	}

	public boolean onSingleTapUp(MotionEvent paramMotionEvent) {
		return false;
	}

	public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
		if (Build.VERSION.SDK_INT >= 14)
			return this.mGestureDetector.onTouchEvent(paramMotionEvent);
		return super.onTouchEvent(paramMotionEvent);
	}
}